package ltd.jdsoft.cute.mybatis;

import java.util.Set;

import org.apache.ibatis.type.Alias;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.reflections.Reflections;

import ltd.jdsoft.cute.common.extention.ExtensionLoader;

/**
 * 自动识别所有注解了@Alias的model，并自动设置别名
 * 
 * @author zhengzhq
 *
 */
public class AliaseSqlSessionFactoryBean extends SqlSessionFactoryBean {

  @Override
  public void setTypeAliases(Class<?>[] typeAliases) {
    Reflections reflections = new Reflections(ExtensionLoader.BASE_PACKAGE);
    Set<Class<?>> classSet = reflections.getTypesAnnotatedWith(Alias.class);
    super.setTypeAliases(classSet.toArray(new Class<?>[] {}));
  }
}
